/**
 * Created by pc126 on 2016/9/7.
 */
import { Injectable } from '@angular/core';
import { Http, Response, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/Rx';

@Injectable()
export class LiveService{
    constructor(private http: Http) {
    }
    getLiveCover( callback = undefined,errorCallback =undefined ){
      var url = 'http://app2.me-to-me.com/api/live/liveCover';
      //  var url = 'http://192.168.89.205:8080/api/live/liveTimeline';
      var body = "uid=295&token=76cfdad8ebe94ef9abe6b1e0fa3695e3&appId=110202&topicId=1317&sinceId=0&security={\"appId\":\"100201\",\"currentTime\":\"1471077216791\",\"nonce\":\"043eb17ae3eb4bc09407e63b3bb10a12\",\"sign\":\"aa35ad90185ba7760a9a9bd2b587610af385a761\"}"
      var headers = new Headers();
      headers.append('Content-Type', 'application/x-www-form-urlencoded');

      return this.http.post(url, body, {
        headers: headers
      })
        .map((res: Response) => res.json())
        .subscribe(function (res: Response) {
          let origin_data = res;
          if (typeof callback === 'function') {
            callback(origin_data);
          }
        }.bind(this), function (error) {
          if (errorCallback && typeof errorCallback === 'function')
            errorCallback(error);
        }.bind(this));
    }
    getLiveList( callback = undefined,errorCallback =undefined ){
        var url = 'http://app2.me-to-me.com/api/live/liveTimeline';
        //  var url = 'http://192.168.89.205:8080/api/live/liveTimeline';
        var body = "uid=295&token=76cfdad8ebe94ef9abe6b1e0fa3695e3&appId=110202&topicId=1317&sinceId=0&security={\"appId\":\"100201\",\"currentTime\":\"1471077216791\",\"nonce\":\"043eb17ae3eb4bc09407e63b3bb10a12\",\"sign\":\"aa35ad90185ba7760a9a9bd2b587610af385a761\"}"
        var headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');

        return this.http.post(url, body, {
          headers: headers
        })
            .map((res: Response) => res.json())
            .subscribe(function (res: Response) {
              let origin_data = res;

              if (typeof callback === 'function') {
                callback(origin_data);
              }
            }.bind(this), function (error) {
              if (errorCallback && typeof errorCallback === 'function')
                errorCallback(error);
            }.bind(this));
    }
}
